<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    function myReverse(head, tail) {
      let pre = null;
      let cur = head;

      let nex = null;
      while (pre != tail) {
        nex = cur.next;
        cur.next = pre;
        pre = cur;
        cur = nex;
      }
      return [tail, head];
    }
    console.log(myReverse([1, 2, 3, 4, 5], 2))


  </script>
</body>

</html>